package com.ts.api.http.infoflow.biz;

import com.gitee.apanlh.util.base.ChooseEq;
import com.gitee.apanlh.util.base.Eq;
import com.gitee.apanlh.util.dataformat.JsonUtils;
import com.ts.api.module.api.convert.core.annotation.ApiReceive;
import com.ts.api.module.api.convert.infoflow.handler.ApiInfoFlowConvertHandler;
import com.ts.api.module.api.entity.ApiUserRequest;
import com.ts.api.module.api.entity.vo.ReqGuangDianTongFormsVO;
import com.ts.api.module.api.entity.vo.ReqGuangDianTongVO;

/**
 *  账号id-49260038
 *  @author Pan
 */
@ApiReceive(apiClientId = "1892614480127217664")
public class ApiInfoFlowTc49260038 implements ApiInfoFlowConvertHandler {

    @Override
    public ApiUserRequest convert(ReqGuangDianTongVO gdtVO) throws Exception {
        ApiUserRequest apiUserRequest = new ApiUserRequest();
        //  表单流程
        ReqGuangDianTongFormsVO bundle = JsonUtils.toBean(gdtVO.getBundle(), ReqGuangDianTongFormsVO.class);
        //  年龄
        apiUserRequest.setAge(gdtVO.getAge());
        //  姓名
        apiUserRequest.setUserName(gdtVO.getUserName());
        //  电话号码
        apiUserRequest.setPhone(gdtVO.getPhone());
        //  设置城市
        apiUserRequest.setCity(gdtVO.getConvertAreaName());
        apiUserRequest.setAreaCode(gdtVO.getConvertAreaCode());

        //  性别转换
        ChooseEq.create(gdtVO.getSex())
            .when("GENDER_TYPE_UNKNOWN", () -> apiUserRequest.setSex("2"))
            .when("GENDER_TYPE_FEMALE", () -> apiUserRequest.setSex("1"))
            .when("GENDER_TYPE_MALE", () -> apiUserRequest.setSex("0"))
        .end();

        //  转化申请额度 申请额度 0-5万 5-10万 10-15万 15-20万
        ChooseEq.create(bundle.getLoanAmount())
          .when("0-5万", () -> apiUserRequest.setLoanAmount("1"))
          .when("5万-10万", () -> apiUserRequest.setLoanAmount("2"))
          .when("5-10万", () -> apiUserRequest.setLoanAmount("2"))
          .when("10万-20万", () -> apiUserRequest.setLoanAmount("3"))
          .when("10-20万", () -> apiUserRequest.setLoanAmount("3"))
          .when("15-20万", () -> apiUserRequest.setLoanAmount("3"))
          .when("20万以上", () -> apiUserRequest.setLoanAmount("4"))
        .end();

        //  表单项默认设置无
        apiUserRequest.setCarInfo("1");
        apiUserRequest.setRealEstateInfo("1");
        apiUserRequest.setProvidentFund("1");
        apiUserRequest.setSocialSecurity("1");
        apiUserRequest.setCareer("1");

        //  表单
        String forms = bundle.getForms();
        //  映射表单
        if (Eq.str("名下有车", forms)) {
            apiUserRequest.setCarInfo("4");
        }
        if (Eq.str("名下有房", forms)) {
            apiUserRequest.setRealEstateInfo("4");
        }
        if (Eq.str("有公积金", forms)) {
            apiUserRequest.setProvidentFund("4");
        }
        if (Eq.str("有社保", forms)) {
            apiUserRequest.setSocialSecurity("4");
        }
        if (Eq.str("有营业执照", forms)) {
            apiUserRequest.setCareer("3");
        }
        return apiUserRequest;
    }
}
